package tencent;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main2 {

    public static int getMinLag(int n, int[] lagTime, Map<Integer,Integer> cache){
        int minIndex = 0;
        int maxIndex = n-1;

        int maxTime = 0;
        for (;maxIndex>=minIndex;){
            Integer minNum = cache.get(lagTime[minIndex]);
            Integer maxNum = cache.get(lagTime[maxIndex]);
            int temp = lagTime[minIndex] + lagTime[maxIndex];
            maxTime = maxTime > temp ? maxTime : temp;

            if (maxNum>minNum) {
                cache.put(lagTime[maxIndex],maxNum-minNum);
                minIndex++;
            }else if (maxNum<minNum){
                cache.put(lagTime[minIndex],minNum - maxNum);
                maxIndex--;
            }else{
                minIndex++;
                maxIndex--;
            }
        }

        return maxTime;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] lagTime = new int[n];
        HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();

        for (int i=0;i<n;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            lagTime[i] = y;
            cache.put(y,x);
        }

        Arrays.sort(lagTime);
        int minLag = getMinLag(n, lagTime, cache);
        System.out.print(minLag);
    }
}
